﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dto;
using bus;
namespace HOANGVIET
{
    public partial class ThemHocSinhVaoLop : Form
    {
        public ThemHocSinhVaoLop(KetNoiDto ketnoi,DANGKYHOCdto dto)
        {
            InitializeComponent();
            dangkyhocBUS = new DANGKYHOCBus(ketnoi);
            dangkyhocDTO = new DANGKYHOCdto();
            hocsinhBUS = new HOCSINHBus(ketnoi);
            dangkyhocDTO = dto;
        }
        #region bien
        DANGKYHOCdto dangkyhocDTO;
        DANGKYHOCBus dangkyhocBUS;
        HOCSINHBus hocsinhBUS;
        #endregion
        #region ham
        public void loadform()
        {
            if (dangkyhocDTO.IDDANGKYHOC == 0)
            {
                buttonX1.Text = "THÊM";
                radioButton2.Visible = false;
                radioButton3.Visible = false;
                radioButton4.Visible = false;
                radioButton1.Checked = true;
            }
            else
            {
                buttonX1.Text = "SỬA";
            }

            DataTable dt = new DataTable();
            dt = dangkyhocBUS.LayDanhSachHocSInhChuaTUngCoLop();
            AutoCompleteStringCollection auto3 = new AutoCompleteStringCollection();
            comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            foreach (DataRow row in dt.Rows)
            {
                auto3.Add(row["TENHOCSINH"].ToString());
            }
            comboBox1.AutoCompleteCustomSource = auto3;
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "TENHOCSINH";
            comboBox1.ValueMember = "IDHOCSINH";
        }
        #endregion
        #region su kien
        #endregion
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                if (buttonX1.Text.Equals("THÊM"))
                {
                    dangkyhocDTO.IDHOCSINH = int.Parse(comboBox1.SelectedValue.ToString());
                    dangkyhocDTO.NGAYDANGKY = dateTimePicker1.Value.Date;
                    dangkyhocDTO.TRANGTHAI = 1;
                    dangkyhocDTO.GHICHU = textBox1.Text;
                    dangkyhocBUS.Them(dangkyhocDTO);
                    this.Close();
                }
            }
            catch (Exception)
            {
            }
        }
    }
}
